<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body>
<form class="layui-form" id="editRole" style="margin-top: 15px;">
    <input type="password" id="id" name="id" style="display: none">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" id="username" name="username" style="width: 300px" required  lay-verify="required"  autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="gender" value="1" title="男">
            <input type="radio" name="gender" value="0" title="女" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-block">
            <input type="text" id="phone" style="width: 300px" name="phone" required  lay-verify="required" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">角色</label>
        <div class="layui-input-block">
            <div id="demo1" class="xm-select-demo" style="width: 300px"></div>
        </div>
    </div>
</form>
<button id="roleList" type="button" style="display: none"></button>
</body>

<script th:src="@{/layui/layui.js}"></script>
<script th:src="@{/layui/xm-select.js}"></script>
<script>
    layui.use(['form','jquery'], function() {
        var form = layui.form
        var $ = layui.jquery

        var id = `[[${id}]]`+""



        $.post("/getUserById",{id:id},function (data) {
            $("#username").val(data.data.username)
            $("#phone").val(data.data.phone)
            $("#id").val(data.data.id)
            let prop = $("input[value='"+data.data.gender+"']").next().children("i").click();
        })

        var demo1 = xmSelect.render({
            el: '#demo1',
            autoRow: true,
            filterable: true,
            direction: 'down',
            height:'600px',
            tree: {
                show: true,
                showFolderIcon: true,
                showLine: true,
                indent: 20,
                expandedKeys: [ -3 ],
            },
            toolbar: {
                show: true,
                list: ['ALL', 'REVERSE', 'CLEAR']
            },
            data(){
                var roleList;
                $.ajax({
                    type: 'post',
                    async : false,
                    url: '/getRoleListAndUserRole',
                    data: {uid:id},//'ids='+arr+'&_method=delete',
                    success: function(data){
                        roleList = data
                    },
                    error: function(data){
                        layer.msg(data.message, {icon: 2,time:1000});
                    }
                });
                return roleList
            }
        })

        $("#roleList").click(function () {
            let value = demo1.getValue("value");
            $(this).val(value)
        })
    })


</script>
</html>